package com.songlanyun.modules.rabbitmq.mq.consumer;

import cn.hutool.core.util.ObjectUtil;
import com.rabbitmq.client.Channel;
import com.songlanyun.common.enums.UserBillConstant;
import com.songlanyun.common.utils.StrUtil;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.coupon.service.CouponReceiveRecordService;
import com.songlanyun.modules.pointconfig.entity.PointConfig;
import com.songlanyun.modules.pointconfig.service.PointConfigService;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.usergains.service.UserBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 会员注册成功
 */
@Component
@Slf4j
public class UserRegSuccessConsumer extends BaseConsumer {

    @Autowired
    private UserBillService userBillService;

    @Autowired
    private PointConfigService pointConfigService;

    @Override
    protected void process(Message message) {
        Long userId = ClassConvertUtils.objToLong(new String(message.getBody()));
        PointConfig config = pointConfigService.loadConfig(true);
        if (ObjectUtil.isNotNull(config))
        {
            userBillService.inBill(userId,
                    "首次注册送贡献值",
                    UserBillConstant.InnerMode.REGISTER,
                    config.getRegisterGiveConsumption(),
                    "","系统");
        }

    }

    @RabbitListener(queues = MqConstant.UserRegSuccessConstant.USER_REG_SUCCESS_QUEUE)
    public void consume(Message message, Channel channel) throws IOException {
        super.handle(message,channel);
    }
}
